/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.abstractvoid.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import org.scilab.forge.jlatexmath.TeXConstants;
import org.scilab.forge.jlatexmath.TeXFormula;
import org.scilab.forge.jlatexmath.TeXIcon;
import pl.abstractvoid.languages.LanguageProvider;

/**
 * Displays the help document. Simple JFrame with JScroll pane.
 * @author Ivo Zieliński
 */
public class HelpJFrame extends JFrame {

    public HelpJFrame() {
        setTitle(LanguageProvider.getInstance().getString("userManual"));
        TeXFormula formula;
        try {
            formula = new TeXFormula(UtilsGUI.readFile("/Documents/Manual_"
                    + LanguageProvider.getInstance().getCurrentLanguageCode() + ".tex"));
        } catch (IOException ex) {
            formula = new TeXFormula("\\text{" + LanguageProvider.getInstance().getString("unableToReadHelp") + "}");
        }
        TeXIcon ti = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 15);
        BufferedImage image = new BufferedImage(ti.getIconWidth(), ti.getIconHeight(),
                BufferedImage.TYPE_4BYTE_ABGR);
        JLabel label = new JLabel(new ImageIcon(image));
        label.setBackground(Color.white);
        ti.paintIcon(label, image.createGraphics(), 0, 0);
        getContentPane().setLayout(new java.awt.GridLayout(1, 1));
        JPanel panel = new JPanel();
        panel.setBackground(Color.white);
        panel.add(label);
        getContentPane().add(new JScrollPane(panel));
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        pack();
        screenSize.setSize(0.9d*screenSize.getWidth(), 0.9d*screenSize.getHeight());
        setSize(screenSize);
        setLocationRelativeTo(null);
        setVisible(true);
    }
}
